package ch.ebnoether.controller;

import java.awt.event.MouseEvent;
import javax.swing.JTextField;

import ch.ebnoether.gui.WinnerCardLeft;
import ch.ebnoether.gui.WinnerCardRight;
import ch.ebnoether.gui.YatzyGUI;
import ch.ebnoether.wuerfel.Dice;

public class EinerController extends MasterController {
  private Dice[] dices;
  private int wuerfelArt;
  private WinnerCardLeft links;
  private WinnerCardRight rechts;

  public EinerController(Dice[] dices, int art, WinnerCardLeft links, WinnerCardRight rechts, YatzyGUI yatzi) {
    super(dices, yatzi);
    this.dices = dices;
    this.wuerfelArt = art;
    this.links = links;
    this.rechts = rechts;
  }

  @Override
  public void mouseClicked(MouseEvent e) {
    Object o = e.getSource();
    JTextField t = (JTextField) o;

    if (!super.isGesetzt() && MasterController.setzbar) {
      t.setText("" + ControllerLogik.zaehleGleicheArt(this.dices, this.wuerfelArt));
      ControllerLogik.setTotalLinks(this.links, ControllerLogik.zaehleGleicheArt(this.dices, this.wuerfelArt));
      ControllerLogik.setTotalRechts(this.rechts, 0);
      super.mouseClicked(e);
    }
  }

  @Override
  public void mouseEntered(MouseEvent e) {
    Object o = e.getSource();
    JTextField t = (JTextField) o;

    if (!super.isGesetzt() && MasterController.setzbar) {
      t.setText("" + ControllerLogik.zaehleGleicheArt(this.dices, this.wuerfelArt));
    }
  }
}
